#include <iostream>
#include <string>

#include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
#include "cgicc/HTMLClasses.h"

#include "CgiWrapper.h"

using std::cout;
using std::endl;
using std::string;
using namespace cgicc;

void CGIWrapper::HTMLHeader()
{
    cout << HTTPHTMLHeader() << endl;
    cout << HTMLDoctype(HTMLDoctype::eStrict) << endl;
}

void CGIWrapper::BeginHtml(const std::string& lang)
{
    cout << html().set("lang", lang.c_str()).set("dir", "LTR") << endl;
}
void CGIWrapper::EndHtml()
{
    cout << html() << endl;
}

void CGIWrapper::Meta(const string& httpEquiv,
	const string& content)
{
    cout << meta().set("http-equiv", httpEquiv).set("content", content);
}

void CGIWrapper::BeginHead(const std::string& titlename,
	const std::string& charset)
{
	cout << head() << endl
	     << title(titlename) << endl
	     << meta().set("http-equiv", "Content-Type").set("content", "text/html") << endl
	     << meta().set("http-equiv", "charset").set("content", charset) << endl << endl;
}
void CGIWrapper::EndHead()
{
    cout << head() << endl;
}

void CGIWrapper::BeginBody()
{
    cout << body() << endl;
}
void CGIWrapper::EndBody()
{
    cout << body() <<endl;
}

void CGIWrapper::H1(const std::string& text)
{
    cout << h1(text.c_str()) << endl;
}

void CGIWrapper::BeginP()
{
    cout << p() << endl;
}
void CGIWrapper::EndP()
{
    cout << p() << endl;
}

void CGIWrapper::BeginForm(const std::string& action,
	const std::string& method)
{
    cout << form().set("action", "/cgi-bin/verify").set("method", "post") << endl;
}
void CGIWrapper::EndForm()
{
    cout << form() << endl;
}

void CGIWrapper::Input(const std::string& type,
	const std::string& name,
	const std::string& value)
{
    input inputhtml;
    inputhtml.set("type", type.c_str()).set("name", name.c_str());
    if (!value.empty())
      inputhtml.set("value", value.c_str());
    cout << inputhtml << endl;
}

void CGIWrapper::HtmlText(const std::string& text)
{
    cout << text.c_str();
}

void CGIWrapper::Br()
{
    cout << br();
}

 
